/**
 * Ingenius-Group S.A.S
 *
 * Project: SAU
 * File: Scale.java
 * Date: 16/11/2010
 */

package com.ingenius.sau.shared.model.core;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.FetchGroup;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.NullValue;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

/**
 * Class <strong>Scale</strong>
 * 
 * @author Jesus David
 * @version 0.1
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
@FetchGroup(name = "with_ranges", members = { @Persistent(name = "ranges") })
public class Scale implements BaseBean {

	// DATA

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
	private String id;

	@Persistent(nullValue = NullValue.NONE)
	private float min = 0;

	@Persistent(nullValue = NullValue.NONE)
	private float max = 10;

	@Persistent(nullValue = NullValue.NONE)
	private float passingScore = 5;

	// CONSTRUCTORS

	public Scale() {
	}

	public Scale(String id) {
		this.id = id;
	}

	// METHODS

	public String getId() {
		return id;
	}

	public float getMin() {
		return min;
	}

	public void setMin(float min) {
		if (min >= 0 && min < max) {
			this.min = min;
		} else {
			System.out
					.println("Error, min should be greater or equal than zero.");
		}
	}

	public float getMax() {
		return max;
	}

	public void setMax(float max) {
		if (max > min) {
			this.max = max;
		} else {
			System.out.println("Error, max should be greater than min.");
		}
	}

	public float getPassingScore() {
		return passingScore;
	}

	public void setPassingScore(float passingScore) {
		if (passingScore > min && passingScore < max) {
			this.passingScore = passingScore;
		} else {
			System.out
					.println("Error, passing score should be between min and max.");
		}
	}

	@Override
	public String toString() {
		return "Min: " + min + "  -  Max: " + max + "  -  Passing score: "
				+ passingScore;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Scale) {
			return ((Scale) obj).getId().equals(id);
		}
		return false;
	}

	@Override
	public Scale toDTO() {
		return this;
	}

}
